package com.llyb.chap02;

import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo {

    private ReentrantLock lock = new ReentrantLock(true);

    public void a(){
        lock.lock();
        b();
        System.out.println("进入a方法");
        lock.unlock();
    }

    private void b() {
        lock.lock();
        System.out.println("进入b方法");
        lock.unlock();
    }


    public static void main(String[] args) {
        new ReentrantLockDemo().a();
        //进入b方法
        //进入a方法  说明synchronized 和 ReentrantLock 都是可重入锁
    }
}
